<template>
	<div style="height:100%">
		<cl-crud @load="onLoad">
			<template #table-column-date="{scope}">
				{{ scope.row.startTime }} -- {{ scope.row.endTime }}
			</template>
			<template #table-column-status="{scope}">
				<el-tag v-if="scope.row.status == 1" type="success">显示</el-tag>
				<el-tag type="info" v-else>不显示</el-tag>
			</template>
		</cl-crud>
	</div>
</template>

<script>
import moment from 'moment';
export default {
	data() {
		return {};
	},

	mounted() {},

	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.integralMall.bwbtBroadcast)
				.set('table', {
					columns: [
						{
							prop: 'content',
							label: '公告内容',
							align: 'center'
						},
						{
							prop: 'date',
							label: '时间',
							align: 'center'
						},
						{
							prop: 'status',
							label: '状态',
							align: 'center'
						}
					],
					op: {
						layout: ['edit', 'delete']
					}
				})
				.set('upsert', {
					props: {
						width: '500px'
					},
					items: [
						{
							prop: 'startTime',
							label: '开始时间',
							value: moment().format('YYYY-MM-DD 00:00:00'),
							component: {
								name: 'el-date-picker',
								props: {
									type: 'datetime'
								}
							},
							rules: [
								{
									required: true,
									message: '请选择开始时间',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'endTime',
							label: '结束时间',
							value: moment().format('YYYY-MM-DD 23:59:59'),
							component: {
								name: 'el-date-picker',
								props: {
									type: 'datetime'
								}
							},
							rules: [
								{
									required: true,
									message: '请选择结束时间',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'content',
							label: '公告内容',
							component: {
								name: 'el-input',
								props: {
									type: 'textarea'
								}
							}
						},
						{
							prop: 'status',
							label: '状态',
							value: 0,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '显示',
										value: 1
									},
									{
										label: '不显示',
										value: 0
									}
								]
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn'],
					['data-table'],
					['flex1', 'pagination']
				])

				.on('submit', async (isEdit, data, { next }) => {
					console.log(data);
					next({
						...data
					});
				})
				.done();
			app.refresh();
		}
	}
};
</script>
<style lang="scss" scoped></style>
